package com.itheima.hmshopping.app.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.hmshopping.dubbo.api.SmsFlashPromotionApi;
import com.itheima.hmshopping.entity.SmsFlashPromotion;
import com.itheima.hmshopping.util.HmPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class SmsFlashPromotionService {


    @DubboReference
    private SmsFlashPromotionApi smsFlashPromotionApi;

    /**
     * 添加活动
     * @param smsFlashPromotion
     */
    public void create(SmsFlashPromotion smsFlashPromotion) {

      smsFlashPromotionApi.create(smsFlashPromotion);

    }

    /**
     * 删除活动
     * @param id
     */
    public void delete(Integer id) {
        smsFlashPromotionApi.delete(id);

    }

    /**
     * 根据活动名称分页查询
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    public HmPage list(String keyword, Integer pageNum, Integer pageSize) {
        Page page=smsFlashPromotionApi.list(keyword,pageNum,pageSize);
        HmPage hmPage=new HmPage();
        //设置总页数
        hmPage.setTotalPage(Convert.toInt(page.getPages()));
        //查询数据
        hmPage.setList(page.getRecords());
        //第几页
        hmPage.setPageNum(Convert.toInt(pageNum));
        //总页数
        hmPage.setTotal(Convert.toInt(page.getTotal()));
        //每页条数
        hmPage.setPageSize(pageSize);
        return hmPage;

    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     */
    public void updateStatus(Integer id, Integer status) {
    smsFlashPromotionApi.updateStatus(id,status);
    }

    /**
     * 编辑活动
     * @param id
     * @param promotion
     */
    public void update(Integer id, SmsFlashPromotion promotion) {
     smsFlashPromotionApi.update(id,promotion);
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    public SmsFlashPromotion getOne(Integer id) {

     return smsFlashPromotionApi.getOne(id);
    }
}
